/**
 * Created by Administrator on 2016/11/15.
 */
function showPic(whichpic) {
    var placeholder = document.getElementById('placeholder');
    if (!placeholder) {
        return false;
    }
    var source = whichpic.getAttribute('href');
    if (placeholder.nodeName != 'IMG') {
        return false;
    }
    placeholder.setAttribute('src', source);
    var description = document.getElementById('description');
    if (description) {
        description.firstChild.nodeValue = whichpic.getAttribute('title');
    }
    return true;
}

function prepareGallery() {
    var supported = document.getElementsByTagName && document.getElementById;
    if (!supported) {
        return false;
    }

    var gallery = document.getElementById('image-gallery');
    if (!gallery) {
        return false;
    }

    var links = gallery.getElementsByTagName('a');
    for (var i = 0; i < links.length; i++) {
        links[i].onclick = function () {
            return !showPic(this);
        };
    }
}

function addLoadEvent(fn) {
    var oldOnload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = fn;
    } else {
        window.onload = function () {
            oldOnload();
            fn();
        }
    }
}

addLoadEvent(prepareGallery);